import 'package:flustars/flustars.dart';
import 'package:flutter/material.dart';
import 'package:flutter_app_study/fragment/channel/ChannelFragment.dart';
import 'package:flutter_app_study/fragment/dynamic/DynamicFragment.dart';
import 'package:flutter_app_study/fragment/home/HomeFragment.dart';
import 'package:flutter_app_study/fragment/shop/ShopFragment.dart';
import 'package:flutter_app_study/utils/ScreenAdapter.dart';
import 'package:flutter_app_study/view/BottomView.dart';
import 'package:flutter_custom_dialog/flutter_custom_dialog.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';

class BiliActivity extends StatefulWidget {
  @override
  _BiliActivityState createState() => _BiliActivityState();
}

class _BiliActivityState extends State<BiliActivity> {
  var pageList = <Widget>[];
  var pageIndex = 0;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    pageList.add(HomeFragment());
    pageList.add(ChannelFragment());
    pageList.add(DynamicFragment());
    pageList.add(ShopFragment());
  }

  @override
  Widget build(BuildContext context) {
    init(context);
    initAy();
    return Scaffold(
      body: pageList[pageIndex],
      bottomSheet: BottomView(bottomViewSelected, pageIndex),
    );
  }

  Function bottomViewSelected(var index) {
    this.pageIndex = index;
    setState(() {});
  }
  void initAy() async {
    await SpUtil.getInstance();
  }

  void init(BuildContext context) {
    //https://github.com/OpenFlutter/flutter_screenutil/blob/master/README_CN.md
    //填入设计稿中设备的屏幕尺寸
    //默认 width : 1080px , height:1920px , allowFontScaling:false
    ScreenAdapter.init(context);
    //假如设计稿是按iPhone6的尺寸设计的(iPhone6 750*1334)
    ScreenAdapter.init(context, width: 750, height: 1334);
    //设置字体大小根据系统的“字体大小”辅助选项来进行缩放,默认为false
    ScreenAdapter.init(context, width: 750, height: 1334, allowFontScaling: true);
    YYDialog.init(context);
    EasyLoading.instance
      ..displayDuration = const Duration(milliseconds: 2000)
      ..indicatorType = EasyLoadingIndicatorType.fadingCircle
      ..loadingStyle = EasyLoadingStyle.light
      ..indicatorSize = 45.0
      ..radius = 10.0
      ..backgroundColor = Colors.green
      ..indicatorColor = Colors.yellow
      ..textColor = Colors.yellow
      ..maskColor = Colors.blue.withOpacity(0.5)
      ..userInteractions = true;
  }
}
